﻿using System.Data.Entity;
using DemoLib.Shared.Models;

namespace DemoLib.Data.Contexts
{
    public class DemoDataContext : DbContext
    {
        public DemoDataContext()
        { }

        public DemoDataContext(string connectionString)
            : base(connectionString)
        {

        }

        public DbSet<User> Users { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<News> News { get; set; }
        public DbSet<UserTask> Tasks { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().ToTable("User");
            modelBuilder.Entity<Role>().ToTable("Role");
            modelBuilder.Entity<News>().ToTable("News");
            modelBuilder.Entity<UserTask>().ToTable("Task");
            modelBuilder.Entity<PublicUser>()
                .Map(x=>x.Properties(p=> new
                    {
                        p.Addess
                        
                    })).ToTable("PublicUser");

            modelBuilder.Entity<InternalUser>()
                .Map(x => x.Properties(p => new
                {
                    p.Dept

                })).ToTable("InternalUser","dbo");
        }

        public override int SaveChanges()
        {
            return base.SaveChanges();
        }
    }
}
